<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<form id="commonconfig_form" action="" method="post" class="smart-form">
    <input type="hidden" name="selectType" id="selectType" value="<s:property value="selectType"/>"/>
    <input type="hidden" id="sType" value="<s:property value="sType"/>"/>
    <input type="hidden" name="keyId" id="keyId" value="<s:property value="keyId"/>"/>
    <fieldset>
        <div class="row">
            <section class="col col-9">
                <div class="inline-group" >
                    <label class="checkbox">
                        <input type="checkbox" name="type" value="0001" />
                        <i></i>角色
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="type" value="0010" />
                        <i></i>部门
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="type" value="1000" />
                        <i></i>岗位
                    </label>
                    <label class="checkbox">
                        <input type="checkbox" name="type" value="0100" />
                        <i></i>职权
                    </label>
                </div>
            </section>
        </div>
        <ul class="list-group">
               <li class="list-group-item">
                  <div id="commonDiv">
                       <div class="row"  id="type-0001" style="display:none">
                           <label class="label col col-2">
                               <a  href="javascript:void(0);" key="btn-choose-role">角色：</a>
                           </label>
                           <section class="col col-5">
                               <label class="input state-disabled">
                                   <input disabled type="text" id="roleName"
                                          value="<s:iterator id="list" value="commonConfig.roleSet"><s:property value="#list.name"/>,</s:iterator>"/>
                                   <input type="hidden" id="roleId" name="roleId"
                                          value="<s:iterator id="list" value="commonConfig.roleSet"><s:property value="#list.id"/>,</s:iterator>"/>
                               </label>
                           </section>
                       </div>
                       <div class="row"  id="type-0010" style="display:none">
                           <label class="label col col-2">
                               <a  href="javascript:void(0);" key="btn-choose-depart">部门：</a>
                           </label>
                           <section class="col col-5">
                               <label class="input state-disabled">
                                   <input  disabled type="text" id="departName"
                                           value="<s:iterator id="list" value="commonConfig.departmentSet"><s:property value="#list.name"/>,</s:iterator>"/>
                                   <input type="hidden" id="departId" name="departId"
                                          value="<s:iterator id="list" value="commonConfig.departmentSet"><s:property value="#list.id"/>,</s:iterator>"/>
                               </label>
                           </section>
                       </div>
                       <div class="row"  id="type-0100" style="display:none">
                           <label class="label col col-2">
                               <a  href="javascript:void(0);" key="btn-choose-power">职权：</a>
                           </label>
                           <section class="col col-5">
                               <label class="input state-disabled">
                                   <input disabled  type="text" id="powerName"
                                          value="<s:iterator id="list" value="commonConfig.powerSet"><s:property value="#list.name"/>,</s:iterator>"/>
                                   <input type="hidden"  id="powerId" name="powerId"
                                          value="<s:iterator id="list" value="commonConfig.powerSet"><s:property value="#list.id"/>,</s:iterator>"/>
                               </label>
                           </section>
                       </div>
                       <div class="row"  id="type-1000" style="display:none">
                           <label class="label col col-2">
                               <a  href="javascript:void(0);" key="btn-choose-post">岗位：</a>
                           </label>
                           <section class="col col-5">
                               <label class="input state-disabled">
                                   <input disabled  type="text" id="postName"
                                          value="<s:iterator id="list" value="commonConfig.postSet"><s:property value="#list.name"/>,</s:iterator>"/>
                                   <input type="hidden" id="postId" name="postId"
                                          value="<s:iterator id="list" value="commonConfig.postSet"><s:property value="#list.id"/>,</s:iterator>"/>
                               </label>
                           </section>
                       </div>
                  </div>
               </li>
        </ul>
    </fieldset>
</form>
<script>
    $(function(){
        $('.chat-footer .textarea-controls').append('<button id="left_foot_btn_save" data="" class="btn btn-sm btn-primary pull-right">确认</button>');
    });
    $("div.modal-body input[name='type']").click(function(){
        var id = $(this).val();
        if($(this).prop("checked")){
            $("div.modal-body #type-"+id).show();
        }else{
            $("div.modal-body #type-"+id).hide();
        }
    });


    $("a[key='btn-choose-role']").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!roleDlg.action",{keyIds:$("div.modal-body #roleId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择角色",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("div.modal-body #roleName").val(name);
                    $("div.modal-body #roleId").val(id);
                }
            });
        });
    });
    $("a[key='btn-choose-depart']").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!departDlg.action",{keyIds:$("div.modal-body #departId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择部门",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("div.modal-body #departName").val(name);
                    $("div.modal-body #departId").val(id);
                }
            });
        });
    });
    $("a[key='btn-choose-post']").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!postDlg.action",{keyIds:$("div.modal-body #postId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择岗位",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("div.modal-body #postName").val(name);
                    $("div.modal-body #postId").val(id);
                }
            });
        });
    });
    $("a[key='btn-choose-power']").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!powerDlg.action",{keyIds:$("div.modal-body #powerId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择职权",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("div.modal-body #powerName").val(name);
                    $("div.modal-body #powerId").val(id);
                }
            });
        });
    });

    $("#left_foot_btn_save").off("click").on("click",function(){
        var actionUrl="ajax-commoncfg!save.action";
        var clone = "";
        form_save("commonconfig_form",actionUrl,{msg:false},function(pdata){
            var data = pdata.data.data[0];
            _show(data);
            clone = $("div.modal-body #commonDiv").clone(true);
            console.debug("#"+data.selectType+"Div");
            $("#"+data.selectType+"Div").empty();


            var keyId=data.keyId;
            $("#"+data.selectType+"Id").val(data.keyId);

            loadURL("ajax-commoncfg!read.action?keyId="+keyId,$("#"+data.selectType+"Div"));
        });

        $(this).leftview('leftClose');
    });

    $(function(){
        var cType=$("input#sType").val();
        console.debug("type :" +cType);
        $("input[name='type']").each(function(i,v){
            var optVal = $(v).val();
            var idx = optVal.indexOf("1");
            if(cType!=null && cType.charAt(idx) == "1"){
                $(v).prop("checked",true);
                $("div.modal-body #type-"+optVal).show();
            }
        });
    });
</script>
